package huawei;

//import java.util.*;
import java.util.*;

class Main2 {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String input = scanner.nextLine();

        Integer length=input.length();
        Integer sumStep=length/4;
        HashMap<Character,Integer> hashMap=new HashMap<>();
        for(Integer i=0;i<length;i++){
            hashMap.put(input.charAt(i),hashMap.getOrDefault(input.charAt(i),0)+1);
        }

        for(Map.Entry<Character,Integer> temp:hashMap.entrySet()){
            temp.setValue(temp.getValue()-sumStep);
        }

        Set<Map.Entry<Character,Integer>> pathCharSet = hashMap.entrySet();
        Iterator<Map.Entry<Character,Integer>> pcSetIterator = pathCharSet.iterator();

        Integer max=Integer.MAX_VALUE;

        for(Integer j=0;j<length;j++){
            Character character=input.charAt(j);
            Integer result=0;
            HashMap<Character,Integer> repeatHashMap=new HashMap<>();
            repeatHashMap.putAll(hashMap);
            if(repeatHashMap.get(character.charValue())>0){
                for(Integer z=j;z<length;z++){
                    Character character1=input.charAt(z);
                    repeatHashMap.put(character1,repeatHashMap.get(character1)-1);
                    result++;
                    if(isBreak(repeatHashMap)){
                        break;
                    }
                }
            }

            if(isBreak(repeatHashMap)){
                max=Math.min(max,result);
            }

        }

        System.out.print(max);
    }

    public static Boolean isBreak(HashMap<Character,Integer> hashMap){
        for (Integer i:hashMap.values()){
            if(i>0){
                return false;
            }
        }
        return true;
    }
}

